
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 2
 * @Author : WangRuoyu 
 * @Date : 2023/5/17 15:35
 */

#include "iostream"

using namespace std;

typedef long long ll;

struct p {
    int idx;
    int value;
};

int main() {
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    p pu[a];
    p pv[b];
    for (int i = 0; i < a; ++i) {
        scanf("%d %d", &pu[i].idx, &pu[i].value);
    }
    for (int i = 0; i < b; ++i) {
        scanf("%d %d", &pv[i].idx, &pv[i].value);
    }

    int x = 0, y = 0;
    ll res = 0;
    while (x < a && y < b) {
        if (pu[x].idx == pv[y].idx) {
            res += (ll) pu[x].value * (ll) pv[y].value;
            x++;
            y++;
        } else if (pu[x].idx > pv[y].idx) {
            y++;
        } else {
            x++;
        }
    }
    cout << res;
    return 0;
}